package gang.org.springframework.boot.web.server;

import gang.org.springframework.boot.web.embedded.tomcat.GangConfigurableWebServerFactory;
import lombok.SneakyThrows;

import java.io.File;
import java.nio.file.Files;

/**
 * @Author：gang.chen
 * @Datetime：2023/9/25 18:18
 */
public class GangAbstractConfigurableWebServerFactory implements GangConfigurableWebServerFactory {

    public int port = 8081;


    public GangShutdown shutdown = GangShutdown.IMMEDIATE;

    @SneakyThrows
    public final File createTemDir(String prefix){

        try {
            File temDir = Files.createTempDirectory(prefix + "." + getPort() + ".").toFile();
            temDir.deleteOnExit();
            return temDir;
        }
        catch (Exception e){
            throw new Exception();
        }
    }

    public int getPort() {
        return port;
    }

    public GangShutdown getShutdown() {
        return shutdown;
    }
}
